package com.gilgamesh.im.handle.server;

import com.gilgamesh.im.common.ServerBootConfiguration;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

/**
* 枚举的单例模式实现服务端消息线程池
**/
public enum ServerMsgHandlePool {

    MSG;

    private ExecutorService executorService;

    private ArrayBlockingQueue<Runnable> blockingDeque;

    ServerMsgHandlePool() {
        /**
         * 初始化阻塞队列
         **/
        this.blockingDeque = new ArrayBlockingQueue<Runnable>(ServerBootConfiguration.MAXBLOCKINGQUEUESIZE);
        /**
         * 初始化线程池
         **/
        this.executorService = new ThreadPoolExecutor(
                ServerBootConfiguration.COREPOOLSIZE,
                ServerBootConfiguration.MAXPOOLSIZE,
                ServerBootConfiguration.ALIVETIME,
                ServerBootConfiguration.TIMEUNIT,
                blockingDeque);
    }

    /**
    * 获取线程池方法
    **/
    public  static ExecutorService getExecutorService() {
        return MSG.executorService;
    }

}
